<html>
  <head>
  <title>Winnipeg Public Library Amazon Search Tool Options</title>
  <script type="text/javascript">

    // Saves options to localStorage.
    function save_options() {
      var select = document.getElementById("alert_level");
      var level = select.children[select.selectedIndex].value;
      localStorage["alert_level"] = level;
      
      select = document.getElementById("check_search");
      var check = select.children[select.selectedIndex].value;
      localStorage["check_search"] = check;

      // Update status to let user know options were saved.
      var status = document.getElementById("status");
      status.innerHTML = "Options Saved.";
      setTimeout(function() {
        status.innerHTML = "";
      }, 750);
    }

    // Restores select box state to saved value from localStorage.
    function restore_options() {

      var optionsTitle = chrome.i18n.getMessage("optionsTitle");
      var titleH1 = document.getElementById("optionsTitle");
      titleH1.innerHTML = optionsTitle;
      
      var optionsAll = chrome.i18n.getMessage("optionsAll");
      var allOption = document.getElementById("opt_all");
      allOption.innerHTML = optionsAll;

      var optionsStock = chrome.i18n.getMessage("optionsStock");
      var stockOption = document.getElementById("opt_stock");
      stockOption.innerHTML = optionsStock;

      var optionsAvailable = chrome.i18n.getMessage("optionsAvailable");
      var availableOption = document.getElementById("opt_available");
      availableOption.innerHTML = optionsAvailable;

      var level = localStorage["alert_level"];
      if (!level) {
        return;
      }
      var select = document.getElementById("alert_level");
      for (var i = 0; i < select.children.length; i++) {
        var child = select.children[i];
        if (child.value == level) {
          child.selected = "true";
          break;
        }
      }
      
      var check = localStorage["check_search"];
      if (!check){return;}
      
      var selectCheck = document.getElementById("check_search");
      for (var i = 0; i < selectCheck.children.length; i++) {
        var child = selectCheck.children[i];
        if (child.value == check) {
          child.selected = "true";
          break;
        }
      }
    }

  </script>

  </head>

  <body onload="restore_options()">
    <h1 id="optionsTitle"></h1>
    <p>
      Alert Level:
      <select id="alert_level">
       <option value="all" id="opt_all"></option>
       <option value="instock" id="opt_stock"></option>
       <option value="available" id="opt_available"></option>
      </select>
    </p>
    <p>
      Check Search Results:
      <select id="check_search">
        <option value="yes" id="check_yes">Enable</option>
        <option value="no" id="check_no">Disable</option>
      </select>
    </p>
    <p>
      <button onclick="save_options()">Save</button>
    </p>
    <div id="status"></div>
    <hr />
    <h2>History</h2>
    <p>Below is the release history and major changes of the extension:</p>
    <ul>
      <li>Version 0.1.0.0, March 27th 2010
        <ul>
          <li>Initial release</li>
          <li>Inserts a notification on Amazon.ca pages with an ISBN in the URL</li>
          <li>Internationalised for English and Japanese (based on browser locale)</li>
        </ul>
      </li>
      <li>Version 0.2.0.0, April 3rd 2010
        <ul>
          <li>Expanded permissions for all known Amazon domains (.fr, .de, .co.jp, etc.)</li>
          <li>Added an options page allowing the user to select under which conditions they are notified of WPL status.</li>
        </ul>
      </li>
      <li>Version 0.3.0.0, April 11th 2010
        <ul>
          <li>Added ability to parse results pages and check every book for Library status.</li>
          <li>The extension will "grey-out" books in a results search page which are not in the library.</li>
          <li>No distinction is made between "In stock and available" and "In stock but not currently available".</li>
          <li>A new Options page setting allows users to Enable or Disable the Search page.</li>
        </ul>
      </li>
    </ul>

  </body>
</html>
